extends Path2D

const DOT_COUNT = 7
var path_follower_list = []
var gap

var parent
# Called when the node enters the scene tree for the first time.
func _ready():
	gap = 0.99 / DOT_COUNT
	parent = get_parent()
	var mark_dot_res = preload ("res://arts/mark_line_point.png")
	# 挂载指示点
	for i in range(DOT_COUNT):
		var new_follower = PathFollow2D.new()
		var follower_sprite = Sprite2D.new()
		follower_sprite.texture = mark_dot_res
		new_follower.add_child(follower_sprite)
		add_child(new_follower)
		path_follower_list.append(new_follower)
	# 挂载最后一个鼠标指向的点
	var top_follower = PathFollow2D.new()
	var top_sprite = Sprite2D.new()
	top_sprite.texture = preload ("res://arts/mark_line_point_top.png")
	top_follower.add_child(top_sprite)
	add_child(top_follower) 
	path_follower_list.append(top_follower)

func _process(_delta):
	if parent.my_status == parent.STATUS.TRIGGER:
		visible = true

		if Input.is_action_pressed("mouse_right"):
			parent.on_click_right()
		# 左键需要用release来判断，考虑到选牌之后可能会按着不放
		# if Input.is_action_just_released("mouse_left"):
		# 	parent.try_play_this_card()
		
		# 计算曲线
		curve.set_point_position(0, Vector2(-10, parent.size.y / 4))
		curve.set_point_position(1, get_local_mouse_position())
		curve.set_point_out(0, Vector2(get_local_mouse_position().x * 0.8,0))
		# 将follower点均匀排布在曲线上
		for i in range(DOT_COUNT + 1):
			path_follower_list[i].progress_ratio = i * gap
	else:
		visible = false
